import shareMixin from "./share";

import { addOpenRecord, saveOpenCollect } from "@/api/modules/career.js";
export default {
  mixins: [shareMixin],
  data() {
    return {
      sharePersonId: "",
      shareChannel: "", //打开渠道 1朋友 2朋友圈 3其他
      shareContent: {
        contentType: 1,
        contentTitle: "",
        contentId: "",
      },
    };
  },
  onLoad(options) {
    // console.log("share---------", options);
    if (this.shareContent.contentType) {
      this.shareContent.contentType = options.contentType;
      this.shareContent.contentTitle = options.contentTitle;
      this.shareContent.contentId = options.contentId;
    }
    if (options.q) {
      let paramStr = decodeURIComponent(options.q).split("?");
      this.optionUrl = decodeURIComponent(options.q);
      let resObj = {};
      if (paramStr[1]) {
        paramStr[1].split("&") &&
          paramStr[1].split("&").forEach((item) => {
            resObj[item.split("=")[0]] = item.split("=")[1];
          });
      }

      if (resObj.hasOwnProperty("sharePersonId")) {
        this.sharePersonId = resObj.sharePersonId;
      }
      if (resObj.hasOwnProperty("shareChannel")) {
        this.shareChannel = resObj.shareChannel;
      }
      if (resObj.hasOwnProperty("positionId")) {
        this.positionId = resObj.positionId;
      }
      if (resObj.hasOwnProperty("shareType")) {
        this.shareType = resObj.shareType;
      }
    } else if (options.hasOwnProperty("sharePersonId")) {
      this.sharePersonId = options.sharePersonId;
      this.shareChannel = options.shareChannel;
      this.positionId = options.positionId;
      this.shareType = options.shareType;
    }
    if (this.sharePersonId && this.positionId) {
      //如果是职业大全下面的页面,就上报一次分享人捏
      // if (this.getCurrentPath().indexOf("/positionDictionary/") != -1) {
      this.reportPositionDictionaryShared();
      // }
    }
  },
  methods: {
    getCurrentPath() {
      const pages = getCurrentPages(); // 获取当前页面栈
      if (pages.length > 0) {
        const currentPage = pages[pages.length - 1]; // 获取当前页面实例对象
        const currentPath = currentPage.route; // 获取当前页面路径
        return currentPath;
      }
    },
    //这个是上报被分享之后进入页面的的 结尾是Shared
    reportPositionDictionaryShared() {
      console.log("进入了reportPositionDictionaryShared");
      console.log("this.positionId", this.positionId);
      console.log(
        "this.sharePersonId--stroge",
        this.sharePersonId,
        uni.getStorageSync("person-id")
      );

      if (true) return;
    },
    reportPositionCollect() {
      if (!this.positionId || !this.sharePersonId) return;
      const saveRecordParams = {
        positionId: this.positionId,
        sharePersonId: this.sharePersonId,
        openPersonId: uni.getStorageSync("person-id").slice(2),
        channel: this.shareChannel ? this.shareChannel : 1,
        platform: 1,
      };
      //适用于未登录人点击，再关注需要调用一次点击事件，传入自己的openId
      if (getApp().globalData.noOpenId == "1") {
        this.reportPositionDictionaryShared();
        getApp().globalData.noOpenId == "0";
        setTimeout(() => {
          saveOpenCollect(saveRecordParams);
        }, 1000);
      } else {
        saveOpenCollect(saveRecordParams);
      }
    },
  },
};
